
# =============================================================================
# APPENDIX L: RUSSIA CASE STUDY PLOT
# Legislative power-sharing score evolution in Russia (1993-2024)
# =============================================================================

# --- PACKAGES ----------------------------------------------------------------
library(ggplot2)
library(dplyr)
library(gridExtra)
library(cowplot)

# --- DATA LOADING ------------------------------------------------------------
data <- read.csv("estimates_independent.csv")

# --- DATA PREPARATION --------------------------------------------------------
subset_data_russia <- data %>%
  filter(
    year >= 1993,
    year <= 2024,
    country_name == "Russia"
  )

# --- VISUALIZATION -----------------------------------------------------------
ru <- ggplot(subset_data_russia, aes(x = year)) +
  # 95% Bayesian credible intervals
  geom_errorbar(
    aes(ymin = dyn.lo, ymax = dyn.up),
    width = 0, linewidth = 0.4, na.rm = TRUE
  ) +
  # Median point estimates
  geom_point(
    aes(y = dyn.estimates),
    size = 1.7, stroke = 0.3, color = "black", na.rm = TRUE
  ) +
  labs(x = "Year", y = "Latent Estimate", title = "") +
  scale_x_continuous(breaks = 1993:2023) +
  scale_y_continuous(limits = c(-2, 2), breaks = seq(-1.5, 1.5, by = 0.5)) +
  theme_bw() +
  theme(
    axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
    plot.title = element_text(hjust = 0.5)
  ) +
  # Leadership transition markers
  geom_vline(xintercept = 1993, linetype = "dotted", linewidth = 0.5) +
  geom_text(aes(x = 1996, y = 1.15, label = "Yeltsin"), inherit.aes = FALSE) +
  geom_vline(xintercept = 1999, linetype = "dotted", linewidth = 0.5) +
  geom_text(aes(x = 2010, y = 1.15, label = "Putin"), inherit.aes = FALSE)

# --- OUTPUT ------------------------------------------------------------------
ggsave("Figure17A.pdf", plot = ru, width = 7, height = 5)
